﻿layui.use(['form', 'layedit', 'layer'], function () {

    var form = layui.form, layer = parent.layer === undefined ? layui.layer : top.layer, $ = layui.jquery, player = parent.layer || layui.layer;

    var authorityAdminAuthorityModifyLogic = {
        //初始化
        init: function () {

            self = this;

            this.Parameters = {
                saveUrl: "/Authority/AdminAuthority/ModifyInfo"
            };

            this.initPage();

            this.bindEvent();

        },
        //初始化列表
        initPage: function () {
            //获取信息
            var data = GrdAssist.queryString("data");
            self.logicFunc.loadInfo(data);
        },
        //绑定事件
        bindEvent: function () {

            //监听立即修改提交
            form.on('submit(modifyButton)', self.logicFunc.saveInfo);

            //关闭
            $("#btnClose").on("click", self.logicFunc.close);

        },
        //逻辑方法
        logicFunc: {

            //获取修改按钮的信息
            loadInfo: function (data) {
                GrdLayUI.assignmentFormData("modify-form", data);
            },
            ///保存数据
            saveInfo: function () {
                var data = GrdLayUI.initParamsData($("#modify-form"));
                if (data.bIsEnabled==1) {
                    data.bIsEnabled = true;
                } else {
                    data.bIsEnabled = false;
                }
                var json = {
                    parameters: data
                };
                GrdLayUI.ajaxPost({
                    url: self.Parameters.saveUrl,
                    data: json,
                    success: function (result) {
                        if (result.Code == 1000) {
                            GrdLayUI.msg(result.Msg, "成功", function () {
                                //获取窗口索引
                                var index = player.getFrameIndex(window.name);
                                //关闭子页面
                                player.close(index);
                                //刷新父页面
                                window.parent.location.reload();
                            });

                        } else {
                            GrdLayUI.msg(result.Msg, "警告");
                        }
                    }
                });
            },
            //取消
            close: function () {
                player.closeAll();
            }
        },
        //工具
        tools: {
        }
    };
    authorityAdminAuthorityModifyLogic.init();
});
